<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>map,filter.reduce的区别 | S.E.</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="一张图及其形象的说明： 一.mapmap() 方法创建一个新数组，其结果是该数组中的每个元素都调用一个提供的函数后返回的结果。用一张图来说明：来自廖雪峰的代码实例：（初学者简单的使用就好了）12345678910let numbers = [1, 5, 10, 15];let doubles = numbers.map((x) =&amp;gt; &amp;#123;   return x * 2;&amp;#125;)">
<meta property="og:type" content="article">
<meta property="og:title" content="map,filter.reduce的区别">
<meta property="og:url" content="http://seveneyes.top/2017/11/03/js高阶函数/index.html">
<meta property="og:site_name" content="S.E.">
<meta property="og:description" content="一张图及其形象的说明： 一.mapmap() 方法创建一个新数组，其结果是该数组中的每个元素都调用一个提供的函数后返回的结果。用一张图来说明：来自廖雪峰的代码实例：（初学者简单的使用就好了）12345678910let numbers = [1, 5, 10, 15];let doubles = numbers.map((x) =&amp;gt; &amp;#123;   return x * 2;&amp;#125;)">
<meta property="og:image" content="http://ow47touqj.bkt.clouddn.com/filter_map_reduce.png">
<meta property="og:image" content="http://ow47touqj.bkt.clouddn.com/QQ%E5%9B%BE%E7%89%8720170922162803.png">
<meta property="og:updated_time" content="2017-11-03T03:41:35.737Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="map,filter.reduce的区别">
<meta name="twitter:description" content="一张图及其形象的说明： 一.mapmap() 方法创建一个新数组，其结果是该数组中的每个元素都调用一个提供的函数后返回的结果。用一张图来说明：来自廖雪峰的代码实例：（初学者简单的使用就好了）12345678910let numbers = [1, 5, 10, 15];let doubles = numbers.map((x) =&amp;gt; &amp;#123;   return x * 2;&amp;#125;)">
<meta name="twitter:image" content="http://ow47touqj.bkt.clouddn.com/filter_map_reduce.png">
  
    <link rel="alternate" href="/atom.xml" title="S.E." type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/css/style.css">
  

</head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">S.E.</a>
      </h1>
      
        <h2 id="subtitle-wrap">
          <a href="/" id="subtitle">成功的人抄袭，伟大的人剽窃</a>
        </h2>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://seveneyes.top"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-js高阶函数" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2017/11/03/js高阶函数/" class="article-date">
  <time datetime="2017-11-03T02:28:52.915Z" itemprop="datePublished">2017-11-03</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      map,filter.reduce的区别
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>一张图及其形象的说明：<br><img src="http://ow47touqj.bkt.clouddn.com/filter_map_reduce.png" alt=""></p>
<h2 id="一-map"><a href="#一-map" class="headerlink" title="一.map"></a>一.map</h2><p>map() 方法创建一个新数组，其结果是该数组中的每个元素都调用一个提供的函数后返回的结果。<br>用一张图来说明：<br>来自廖雪峰的<br>代码实例：（初学者简单的使用就好了）<br><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">let</span> numbers = [<span class="number">1</span>, <span class="number">5</span>, <span class="number">10</span>, <span class="number">15</span>];</div><div class="line"><span class="keyword">let</span> doubles = numbers.map(<span class="function">(<span class="params">x</span>) =&gt;</span> &#123;</div><div class="line">   <span class="keyword">return</span> x * <span class="number">2</span>;</div><div class="line">&#125;);</div><div class="line"><span class="comment">// doubles is now [2, 10, 20, 30]</span></div><div class="line"><span class="comment">// numbers is still [1, 5, 10, 15]</span></div><div class="line"><span class="keyword">let</span> numbers = [<span class="number">1</span>, <span class="number">4</span>, <span class="number">9</span>];</div><div class="line"><span class="keyword">let</span> roots = numbers.map(<span class="built_in">Math</span>.sqrt);</div><div class="line"><span class="comment">// roots is now [1, 2, 3]</span></div><div class="line"><span class="comment">// numbers is still [1, 4, 9]</span></div></pre></td></tr></table></figure></p>
<p><strong>map()的真正的语法：</strong><br><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">let</span> array = arr.map(<span class="function"><span class="keyword">function</span> <span class="title">callback</span>(<span class="params">currentValue, index, array</span>) </span>&#123; </div><div class="line">    <span class="comment">// Return element for new_array </span></div><div class="line">&#125;[, thisArg])</div></pre></td></tr></table></figure></p>
<p>参数说明：<br><strong>callback</strong> 生成新数组元素的函数，使用三个参数：</p>
<ol>
<li>currentValue<br>callback 的第一个参数，数组中正在处理的当前元素。</li>
<li>index<br>callback 的第二个参数，数组中正在处理的当前元素的索引。</li>
<li>array<br>callback 的第三个参数，map 方法被调用的数组。</li>
</ol>
<p><strong>thisArg</strong><br>可选的。执行 callback 函数时 使用的this 值。<br>返回值<br>一个新数组，每个元素都是回调函数的结果。<br>运行说明：<br><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">let</span> a = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>,<span class="number">2</span>,<span class="number">6</span>,<span class="number">10</span>] ;</div><div class="line"><span class="keyword">let</span> b =a.map(<span class="function"><span class="keyword">function</span>(<span class="params">value,index,array</span>)</span>&#123;</div><div class="line">    <span class="built_in">console</span>.log(value,index,array);</div><div class="line">&#125;)</div><div class="line"><span class="comment">//1 0 [1,2,3,4,5,2,6,10]</span></div><div class="line"><span class="comment">//2 1 [1,2,3,4,5,2,6,10]</span></div><div class="line"><span class="comment">//3 2 [1,2,3,4,5,2,6,10]...</span></div></pre></td></tr></table></figure></p>
<p>来自微软的map说明：<br><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line"><span class="comment">// Define an object that contains a divisor property and</span></div><div class="line"><span class="comment">// a remainder function.</span></div><div class="line"><span class="keyword">var</span> obj = &#123;</div><div class="line">    divisor: <span class="number">10</span>,</div><div class="line">    remainder: <span class="function"><span class="keyword">function</span> (<span class="params">value</span>) </span>&#123;</div><div class="line">        <span class="keyword">return</span> value % <span class="keyword">this</span>.divisor;</div><div class="line">    &#125;</div><div class="line">&#125;</div><div class="line"><span class="comment">// Create an array.</span></div><div class="line"><span class="keyword">var</span> numbers = [<span class="number">6</span>, <span class="number">12</span>, <span class="number">25</span>, <span class="number">30</span>];</div><div class="line"><span class="comment">// Get the remainders.</span></div><div class="line"><span class="comment">// The obj argument specifies the this value in the callback function.</span></div><div class="line"><span class="keyword">var</span> result = numbers.map(obj.remainder, obj);</div><div class="line"><span class="built_in">document</span>.write(result);</div><div class="line"><span class="comment">// Output:</span></div><div class="line"><span class="comment">// 6,2,5,0</span></div></pre></td></tr></table></figure></p>
<p>暂时就先这样吧，以后再改<br>碰到的一个有趣的地方</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div></pre></td><td class="code"><pre><div class="line">[<span class="string">"1"</span>,<span class="string">"2"</span>,<span class="string">"3"</span>].map(<span class="built_in">parseInt</span>)<span class="comment">//会得到什么?</span></div><div class="line"><span class="comment">// 你可能觉的会是[1, 2, 3]</span></div><div class="line"><span class="comment">//但是现实总是残酷的</span></div><div class="line"><span class="comment">// 但实际的结果是 [1, NaN, NaN]</span></div><div class="line"><span class="comment">// 通常使用parseInt时,只需要传递一个参数.</span></div><div class="line"><span class="comment">// 但实际上,parseInt可以有两个参数.第二个参数是进制数.</span></div><div class="line"><span class="comment">// 可以通过语句"alert(parseInt.length)===2"来验证.</span></div><div class="line"><span class="comment">// map方法在调用callback函数时,会给它传递三个参数:当前正在遍历的元素, </span></div><div class="line"><span class="comment">// 元素索引, 原数组本身.</span></div><div class="line"><span class="comment">// 第三个参数parseInt会忽视, 但第二个参数不会,也就是说,</span></div><div class="line"><span class="comment">// parseInt把传过来的索引值当成进制数来使用.从而返回了NaN.</span></div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">returnInt</span>(<span class="params">element</span>) </span>&#123;</div><div class="line">  <span class="keyword">return</span> <span class="built_in">parseInt</span>(element, <span class="number">10</span>);</div><div class="line">&#125;</div><div class="line">[<span class="string">'1'</span>, <span class="string">'2'</span>, <span class="string">'3'</span>].map(returnInt); <span class="comment">// [1, 2, 3]</span></div><div class="line"><span class="comment">// 意料之中的结果</span></div><div class="line"><span class="comment">// 也可以使用简单的箭头函数，结果同上</span></div><div class="line">[<span class="string">'1'</span>, <span class="string">'2'</span>, <span class="string">'3'</span>].map( <span class="function"><span class="params">str</span> =&gt;</span> <span class="built_in">parseInt</span>(str) );</div><div class="line"><span class="comment">// 一个更简单的方式:</span></div><div class="line">[<span class="string">'1'</span>, <span class="string">'2'</span>, <span class="string">'3'</span>].map(<span class="built_in">Number</span>); <span class="comment">// [1, 2, 3]</span></div><div class="line"><span class="comment">// 与`parseInt` 不同，下面的结果会返回浮点数或指数:</span></div><div class="line">[<span class="string">'1.1'</span>, <span class="string">'2.2e2'</span>, <span class="string">'3e300'</span>].map(<span class="built_in">Number</span>); <span class="comment">// [1.1, 220, 3e+300]</span></div></pre></td></tr></table></figure>
<h2 id="二-filter"><a href="#二-filter" class="headerlink" title="二.filter"></a>二.filter</h2><p>filter() 方法创建一个新数组, 其包含通过所提供函数实现的测试的所有元素。它叫过滤选择器<br>和上面一样，直接拿代码<br><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">isBigEnough</span>(<span class="params">value</span>) </span>&#123;</div><div class="line">  <span class="keyword">return</span> value &gt;= <span class="number">10</span>;</div><div class="line">&#125;</div><div class="line"><span class="keyword">var</span> filtered = [<span class="number">12</span>, <span class="number">5</span>, <span class="number">8</span>, <span class="number">130</span>, <span class="number">44</span>].filter(isBigEnough);</div><div class="line"><span class="comment">// filtered is [12, 130, 44]</span></div><div class="line"><span class="comment">// ES6 way</span></div><div class="line"><span class="keyword">const</span> isBigEnough = <span class="function"><span class="params">value</span> =&gt;</span> value &gt;= <span class="number">10</span>;<span class="comment">//很骚的函数</span></div><div class="line"><span class="keyword">let</span> [...spraed]= [<span class="number">12</span>, <span class="number">5</span>, <span class="number">8</span>, <span class="number">130</span>, <span class="number">44</span>];<span class="comment">//解构赋值</span></div><div class="line"><span class="keyword">let</span> filtered = spraed.filter(isBigEnough);</div><div class="line"><span class="comment">// filtered is [12, 130, 44]</span></div></pre></td></tr></table></figure></p>
<p>语法可以参考map的，这里就简单说明<br><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> new_array = arr.filter(callback[, thisArg])</div></pre></td></tr></table></figure></p>
<ol>
<li>callback<br>用来测试数组的每个元素的函数。调用时使用参数 (element, index, array)。<br>返回true表示保留该元素（通过测试），false则不保留。</li>
<li>thisArg<br>可选。执行 callback 时的用于 this 的值。<br>返回值<br>一个新的通过测试的元素的集合的数组</li>
</ol>
<h2 id="三-reduce"><a href="#三-reduce" class="headerlink" title="三.reduce"></a>三.reduce</h2><p>reduce() 方法对累加器和数组中的每个元素 (从左到右)应用一个函数，将其减少为单个值。<br><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> total = [<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].reduce(<span class="function"><span class="keyword">function</span>(<span class="params">sum, value</span>) </span>&#123;</div><div class="line">  <span class="keyword">return</span> sum + value;</div><div class="line">&#125;, <span class="number">0</span>);</div><div class="line"><span class="comment">// total is 6</span></div><div class="line"><span class="comment">//居然可以用reduce降维</span></div><div class="line"><span class="keyword">var</span> flattened = [[<span class="number">0</span>, <span class="number">1</span>], [<span class="number">2</span>, <span class="number">3</span>], [<span class="number">4</span>, <span class="number">5</span>]].reduce(<span class="function"><span class="keyword">function</span>(<span class="params">a, b</span>) </span>&#123;</div><div class="line">  <span class="keyword">return</span> a.concat(b);</div><div class="line">&#125;, []);</div><div class="line"><span class="comment">// flattened is [0, 1, 2, 3, 4, 5]</span></div></pre></td></tr></table></figure></p>
<p>语法<br><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">array.reduce(<span class="function"><span class="keyword">function</span>(<span class="params">accumulator, currentValue, currentIndex, array</span>), <span class="title">initialValue</span>)</span></div></pre></td></tr></table></figure></p>
<p>说明<br><strong>callback</strong><br>执行数组中每个值的函数，包含四个参数</p>
<ol>
<li>accumulator<br>上一次调用回调返回的值，或者是提供的初始值（initialValue）</li>
<li>currentValue<br>数组中正在处理的元素</li>
<li>currentIndex<br>数据中正在处理的元素索引，如果提供了 initialValue ，从0开始；否则从1开始</li>
<li>array<br>调用 reduce 的数组</li>
<li>initialValue<br>可选项，其值用于第一次调用 callback 的第一个参数。如果没有设置初始值，则将数组中的第一个元素作为初始值。空数组调用reduce时没有设置初始值将会报错。<br>返回值<br>函数累计处理的结果<br>注意:<br>不提供 initialValue ，reduce 会从索引1的地方开始执行 callback 方法，跳过第一个索引。提供 initialValue ，从索引0开始。</li>
</ol>
<p>如果数组为空并且没有提供initialValue， 会抛出TypeError 。如果数组仅有一个元素（无论位置如何）并且没有提供initialValue， 或者有提供initialValue但是数组为空，那么此唯一值将被返回并且callback不会被执行。</p>
<p>提供 initialValue 通常更安全，正如下面的例子，如果没有提供initialValue，则可能有三种输出：<br><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> maxCallback = <span class="function">(<span class="params"> pre, cur </span>) =&gt;</span> <span class="built_in">Math</span>.max( pre.x, cur.x );</div><div class="line"><span class="keyword">var</span> maxCallback2 = <span class="function">(<span class="params"> max, cur </span>) =&gt;</span> <span class="built_in">Math</span>.max( max, cur );</div><div class="line"><span class="comment">// reduce() without initialValue</span></div><div class="line">[ &#123; <span class="attr">x</span>: <span class="number">22</span> &#125;, &#123; <span class="attr">x</span>: <span class="number">42</span> &#125; ].reduce( maxCallback ); <span class="comment">// 42</span></div><div class="line">[ &#123; <span class="attr">x</span>: <span class="number">22</span> &#125;            ].reduce( maxCallback ); <span class="comment">// &#123; x: 22 &#125;</span></div><div class="line">[                      ].reduce( maxCallback ); <span class="comment">// TypeError</span></div><div class="line"><span class="comment">// map/reduce; better solution, also works for empty arrays</span></div><div class="line">[ &#123; <span class="attr">x</span>: <span class="number">22</span> &#125;, &#123; <span class="attr">x</span>: <span class="number">42</span> &#125; ].map( <span class="function"><span class="params">el</span> =&gt;</span> el.x )</div><div class="line">                        .reduce( maxCallback2, -<span class="literal">Infinity</span> );</div></pre></td></tr></table></figure></p>
<p>reduce的运行<br><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">[<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>].reduce(<span class="function"><span class="keyword">function</span>(<span class="params">accumulator, currentValue, currentIndex, array</span>)</span>&#123;</div><div class="line">  <span class="keyword">return</span> accumulator + currentValue;</div><div class="line"><span class="comment">//箭头操作</span></div><div class="line">[<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>].reduce( <span class="function">(<span class="params">prev, curr</span>) =&gt;</span> prev + curr );</div><div class="line"><span class="comment">//同样的结果</span></div><div class="line">&#125;);</div></pre></td></tr></table></figure></p>
<p>懒得弄表格了，直接上图<br><img src="http://ow47touqj.bkt.clouddn.com/QQ%E5%9B%BE%E7%89%8720170922162803.png" alt=""><br>[相关reduce文档(来自MDN)(<a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce" target="_blank" rel="external">https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce</a>)<br>相信你看了这么多，应该可以简单的使用这三个函数了</p>
<h2 id="再讲一下foreach吧"><a href="#再讲一下foreach吧" class="headerlink" title="再讲一下foreach吧"></a>再讲一下foreach吧</h2><p>forEach() 方法对数组的每个元素执行一次提供的函数。<br><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">let</span> a = [<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>];</div><div class="line">a.forEach(<span class="function"><span class="keyword">function</span>(<span class="params">element</span>) </span>&#123;</div><div class="line">    <span class="built_in">console</span>.log(element);</div><div class="line">&#125;);</div><div class="line"><span class="comment">// a</span></div><div class="line"><span class="comment">// b</span></div><div class="line"><span class="comment">// c</span></div></pre></td></tr></table></figure></p>
<p>语法<br><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">array.forEach(callback(currentValue, index, array)&#123;</div><div class="line">    <span class="comment">//do something</span></div><div class="line">&#125;, <span class="keyword">this</span>)</div><div class="line">array.forEach(callback[, thisArg])</div></pre></td></tr></table></figure></p>
<p>现在，你会发现foreach和map,reduce好像可以通用,的确，在某些方面你随便用哪个都可以。<br>但是，你需要知道foreach的返回值是undefined<br>参数<br><strong>callback</strong><br>为数组中每个元素执行的函数，该函数接收三个参数：</p>
<ol>
<li>currentValue(当前值)<br>数组中正在处理的当前元素。</li>
<li>index(索引)<br>数组中正在处理的当前元素的索引。</li>
<li>array<br>forEach()方法正在操作的数组。<br><strong>thisArg</strong>可选<br>可选参数。当执行回调 函数时用作this的值(参考对象)。<br><strong>返回值</strong><br>undefined.<br>个人不建议使用这个东西，不为什么，就任性 ;<br><a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach" target="_blank" rel="external">详情请参考MND文档</a></li>
</ol>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://seveneyes.top/2017/11/03/js高阶函数/" data-id="cjf9vxkwj0004f4qsozyxaq53" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2017/11/03/用码云挂载页面/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          用码云挂载页面
        
      </div>
    </a>
  
  
    <a href="/2017/11/03/js的number的数据处理/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">js的number的数据处理（取位）</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    

  
    

  
    
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/03/">March 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/11/">November 2017</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2018/03/27/入门教程/">入门教程</a>
          </li>
        
          <li>
            <a href="/2017/11/21/jasmine测试框架的使用/">jasmine测试框架的使用</a>
          </li>
        
          <li>
            <a href="/2017/11/03/用码云挂载页面/">用码云挂载页面</a>
          </li>
        
          <li>
            <a href="/2017/11/03/js高阶函数/">map,filter.reduce的区别</a>
          </li>
        
          <li>
            <a href="/2017/11/03/js的number的数据处理/">js的number的数据处理（取位）</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2018 SevenEyes<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/script.js"></script>

  </div>
</body>
</html>